package com.aube.mis.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.aube.common.req.vo.PaginationReqVo;
import com.aube.mis.vo.DataTableCriterias;
import com.aube.mis.vo.DataTableCriterias.ColumnCriterias;
import com.aube.mis.vo.DataTableCriterias.OrderCriterias;

public abstract class AbstractService {

	private static Logger log = LoggerFactory.getLogger(AbstractService.class);
	
	protected <T> PaginationReqVo<T> fillPaginationInfo(DataTableCriterias criterias) {
		PaginationReqVo<T> vo = new PaginationReqVo<T>();
		vo.setPage(criterias.getStartPage());
		vo.setMaxnum(criterias.getLength());
		List<Map<OrderCriterias, String>> order = criterias.getOrder();
		if(order != null) {
			Map<String, Boolean> sortMap = new HashMap<String, Boolean>();
			for (Map<OrderCriterias, String> map : order) {
				String columnIndex = map.get(OrderCriterias.column);
				String dir = map.get(OrderCriterias.dir);
				String columnName = criterias.getColumns().get(Integer.parseInt(columnIndex)).get(ColumnCriterias.data);
				sortMap.put(columnName, "asc".equals(dir) ? true : false);
			}
			vo.setSortMap(sortMap);
		}
		return vo;
	}
}
